from python并发编程.blog_spider import urls, craw

import threading
import time


def single_thread():
    print("single_thread_begin")
    for url in urls:
        craw(url)
    print("end")


def multi_thread():
    print("multi_thread begin")
    threads = []
    for url in urls:
        threads.append(
            threading.Thread(target=craw, args=(url,))
        )
    for thread in threads:
        thread.start()

    for thread in threads:
        thread.join()
    print("multi_thread end")


if __name__ == '__main__':
    start_time = time.time()
    single_thread()
    end_time = time.time()
    print("single_thread cost:", end_time - start_time)
    start_time = time.time()
    multi_thread()
    end_time = time.time()
    print("mutil_thread cost:", end_time - start_time)
